<?php

/**
 * This is the model class for table "ventas".
 *
 * The followings are the available columns in table 'ventas':
 * @property integer $id
 * @property string $EMPLEADOS_dni
 * @property integer $PRODUCTOS_id
 * @property string $fecha
 * @property string $codigo_boleta
 * @property double $monto
 *
 * The followings are the available model relations:
 * @property Comisiones[] $comisiones
 * @property Empleados $eMPLEADOSDni
 * @property Productos $pRODUCTOS
 */
class Ventas extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Ventas the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ventas';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('EMPLEADOS_dni, PRODUCTOS_id, fecha, codigo_boleta, monto', 'required'),
			array('PRODUCTOS_id', 'numerical', 'integerOnly'=>true),
			array('monto', 'numerical'),
			array('EMPLEADOS_dni, codigo_boleta', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, EMPLEADOS_dni, PRODUCTOS_id, fecha, codigo_boleta, monto', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'comisiones' => array(self::HAS_MANY, 'Comisiones', 'VENTAS_id'),
			'eMPLEADOSDni' => array(self::BELONGS_TO, 'Empleados', 'EMPLEADOS_dni'),
			'pRODUCTOS' => array(self::BELONGS_TO, 'Productos', 'PRODUCTOS_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'EMPLEADOS_dni' => 'Empleados Dni',
			'PRODUCTOS_id' => 'Productos',
			'fecha' => 'Fecha',
			'codigo_boleta' => 'Codigo Boleta',
			'monto' => 'Monto',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('EMPLEADOS_dni',$this->EMPLEADOS_dni,true);
		$criteria->compare('PRODUCTOS_id',$this->PRODUCTOS_id);
		$criteria->compare('fecha',$this->fecha,true);
		$criteria->compare('codigo_boleta',$this->codigo_boleta,true);
		$criteria->compare('monto',$this->monto);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}